package com.example.controller;

import com.example.service.ExchangerExampleService;
import com.example.service.MultiThreadExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/exchanger/example")
public class ExchangerExampleController {

    @Autowired
    private ExchangerExampleService exchangerExampleService;
    @Autowired
    private MultiThreadExchangeService multiThreadExchangeService;

    @GetMapping("/exchanger-example")
    public String executeExchangerTask() {
        // 只适用于两个线程之间交换数据
        exchangerExampleService.executeExchangerTask();
        return "Exchanger 示例任务已启动";
    }

    @GetMapping("/multi-thread-exchange")
    public String executeMultiThreadExchangeTask() {
        // 超过两个线程之间交换数据借助其他工具
        multiThreadExchangeService.executeMultiThreadExchangeTask();
        return "Multi-thread Exchange 示例任务已启动";
    }
}
